//
//  MineViewController.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/4/2.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "MineViewController.h"
#import "UserInfo.h"
#import "LoginViewController.h"
#import "CommonMethod.h"
@interface MineViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic ,strong) NSArray *titles;
@property (nonatomic ,strong) UserInfo *userInfo;
@end

@implementation MineViewController

- (NSArray *)titles {
    if (!_titles) {
        _titles = @[@[@"店铺账号：",@"修改密码"],@[@"退出"]];
    }
    return _titles;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的";
    _userInfo = [UserInfo sharedUserInfo];
    [self createTableView];
}

- (void)createTableView {

    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:(UITableViewStylePlain)];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.view addSubview:self.tableView];
}

#pragma mark - UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.titles.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [self.titles[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *MineCellID = @"MineCellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MineCellID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:MineCellID];
         cell.textLabel.font = [UIFont systemFontOfSize:14];
         cell.textLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    }
    cell.textLabel.text = self.titles[indexPath.section][indexPath.row];
    if (indexPath.section == 0 && indexPath.row == 0) {
       
        cell.detailTextLabel.text = [CommonMethod handlePhoneNumber:_userInfo.yhm];
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 8;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        if (indexPath.row == 1) {
            [self showAlertWith:@"该功能尚未开放！"];
        }
    }
    
    if (indexPath.section == 1) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [UIView beginAnimations:@"exitApplication" context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:NO];
        [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
        window.bounds = CGRectMake(0, 0, 0, 0);
        [UIView commitAnimations];

    }
}

#pragma mark - 退出APP动画
- (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if ([animationID compare:@"exitApplication"] == 0) {
        exit(0);
    }
}
@end
